// pages/category/category.js
let {getCatelist} = require('../../api/Category.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      // 2.静态数据显示页面中
        // 双向数据绑定
        scrollHeight:400,
        num:0,//默认下标
        categoryItem:[
            // "签到",
            // "附近",
            // "展会",
            // "福利",
            // "玩乐",
            // "体育",
            // "周边",
            // "亲子",
        ],
        content:[
            [
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
            ],[
                {
                    img:"/images/goods02.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods02.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
            ],[
                {
                    img:"/images/goods03.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods03.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
            ],
            [
                {
                    img:"/images/goods04.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods04.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
            ],
            [
                {
                    img:"/images/lists01.webp",
                    name:"商品"
                },
                {
                    img:"/images/lists02.webp",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
            ],
            [
                {
                    img:"/images/lists03.webp",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                }, {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },

                {
                    img:"/images/lists04.webp",
                    name:"商品"
                },
            ],
            [
                {
                    img:"/images/lists05.webp",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },

                {
                    img:"/images/lists06.webp",
                    name:"商品"
                },
            ],
            [
                {
                    img:"/images/movie01.jpg",
                    name:"商品"
                },
                {
                    img:"/images/goods01.jpg",
                    name:"商品"
                },
                
                {
                    img:"/images/movie02.jpg",
                    name:"商品"
                },
            ],
        ]
  },
  setNum(options){
        console.log("自定义方法");
        console.log(options.target.dataset.index);
        this.setData({
            num:options.target.dataset.index,
        })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log("onload生命周期函数-生命周期函数--监听页面加载")
         getCatelist().then((data)=>{
          console.log(data);
          let lists = data.message;
          let listsadd=[];
          let imglist=lists;
          // 获取大类别
          lists.forEach((item,index)=>{
            // iconArray[index]=lists[index].cat_name;
            let{cat_id,cat_name,cat_pid}=item
            //    console.log(item)
              let iconArrays ={
                cat_id:cat_id,
                cat_name:cat_name,
                cat_pid:cat_pid
             }
             listsadd.push(iconArrays)
          })
          this.setData({
            categoryItem:listsadd,
            content:imglist
          })
      })

      wx:wx.getSystemInfo({
        
        success: (result) => {
            
            let height =result.windowHeight
            this.setData({
                scrollHeight:height
            })
        },
       
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    // console.log("生命周期函数--监听页面显示","categroyIndex");
    let index = wx.getStorageSync('categroyIndex') || 0;
    // console.log(index);
    this.setData({
        num:index
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})